<?
//package junit.runner;

//import java.lang.reflect.*;
//import junit.runner.*;
//import junit.framework.*;

/**
 * An implementation of a TestCollector that loads
 * all classes on the class path and tests whether
 * it is assignable from Test or provides a static suite method.
 * @see TestCollector
 */
class LoadingTestCollector //extends ClassPathTestCollector 
{	
	public $fLoader;
	
	public function __construct() 
	{
		$this->fLoader= new TestCaseClassLoader();
	}
	
	protected function isTestClass( $classFileName ) 
	{	
		try 
		{
			if ( $classFileName->endsWith(".class")) 
			{
				$testClass = $this->classFromFile( $classFileName ); //class
				return ($testClass != null) && isTestClass( $testClass );
			}
		} 
		catch (ClassNotFoundException $expected) 
		{
		}
		catch (NoClassDefFoundError $notFatal) 
		{
		} 
		return false;
	}
	
	function classFromFile( $classFileName ) //throws ClassNotFoundException {
	{
		$className = $classNameFromFile( $classFileName );
		if ( !$this->fLoader->isExcluded( $className ) )
			return $this->fLoader->loadClass( $className, false );
		return null;
	}
	
	/*function isTestClass( _Class $testClass ) 
	{
		if ( hasSuiteMethod( $testClass ) )
			return true;
		if ( Test.class.isAssignableFrom( $testClass ) &&
			Modifier::isPublic( $testClass->getModifiers() ) &&
			hasPublicConstructor( $testClass )) 
			return true;
		return false;
	}*/
	
	function hasSuiteMethod( _Class $testClass ) 
	{
		try 
		{
			$testClass->getMethod( BaseTestRunner::SUITE_METHODNAME, array( new _Class ) );
	 	} 
	 	catch(Exception $e) 
	 	{
	 		return false;
		}
		return true;
	}
	
	function hasPublicConstructor( _Class $testClass ) 
	{
		try 
		{
			TestSuite::getTestConstructor( $testClass );
		}
		catch(NoSuchMethodException $e) 
		{
			return false;
		}
		return true;
	}
}
?>